﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace EnterpriseInformation.Common
{
    public class RegexClass
    {
        public string RegexString(string input, string pattern, string groupName)
        {

            foreach (Match match in Regex.Matches(input, pattern))
            {
                return match.Groups[groupName].Value.ToString();
            }

            return "";

        }

        public string RegexString(string input, string pattern)
        {
            string value = "";

            foreach (Match match in Regex.Matches(input, pattern))
            {

                value = value + "\t" + match.Value.ToString();

            }

            return value;

        }


        public List<string> RegexListStr(string input, string pattern, string groupOne)
        {
            List<string> listStr = new List<string>();

            foreach (Match match in Regex.Matches(input, pattern))
            {

                listStr.Add(match.Groups[groupOne].Value.ToString());

            }

            return listStr;

        }


        public string AdvanceRegex(string input, string pattern)
        {

            try
            {

                MatchCollection m = Regex.Matches(input, pattern, RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Singleline);

                StringBuilder sb = new StringBuilder();

                if (m.Count > 0)
                {
                    foreach (Match subm in m)
                    {
                        sb.AppendLine(subm.Groups[0].Value);
                    }
                }


                return sb.ToString();

            }
            catch (Exception)
            {

                return "";
            }



        }


    }
}
